//
//  ClubOtherInfoView.swift
//  77Club
//
//  Created by Apple on 2024/10/22.
//

import UIKit


class ClubOtherInfoMoreView: UIView, RaeAnimationProtocol, RaeAnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 265)
    }
    
    func animationContainerViewStyle() -> RaeAnimationViewStyle {
        .bottom
    }
    
    private let userView = c_make_ex(UIView.self)
        .corner(8.0.Scale).bgColor("#F7F8FA").end()
    private let nameLabel = c_make_ex(UILabel.self)
        .color("#2E3033").font(15.font_semiBold).end()
    private let genderImage = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).end()
    private let lineView = c_make_ex(UIView.self)
        .bgColor("#AEB0B3").end()
    private let ageLabel = c_make_ex(UILabel.self)
        .color("#47494D").font(13.font_semiBold).end()
    private let iconCircleView = c_make_ex(UIView.self)
        .bgColor(.clear).corner(22.0.Scale)
        .border("#7B7D80".toColor.alpha(0.12), width: 2.0.Scale).end()
    private let shadowView = c_make_ex(UIView.self)
        .bgColor(.black.alpha(0.1)).end()
    private let iconImageView = c_make_ex(UIImageView.self)
        .mode(.scaleToFill).corner(18.0.Scale).end()
    private let blockButton = c_make_ex(UIButton.self)
        .corner(8.0.Scale).bgColor("#F7F8FA").end()
    private let blockLabel = UIIconButton(style: .leading(itemSpace: 12))
    private let cancelButton = c_make_ex(UIButton.self)
        .corner(8.0.Scale).bgColor(.white).text("取消")
        .font(15.font_semiBold).color("#2E3033").end()
    
    
    var model: ClubMineUserModel?{
        didSet{
            guard let md = model else { return }
            
            self.nameLabel.text = md.user_name
            self.iconImageView.loadImage(url: md.face)
            var imgStr = "Mine_other_female"
            if md.gender == "1"{
                imgStr = "Mine_other_male"
            }else if md.gender == ""{
                imgStr = "Mine_other_medium"
            }
            genderImage.image = imgStr.toImage
            ageLabel.text = md.age
        }
    }
    
    var blockBlock: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = "#E8E9EB".toColor
        rae.corner(12.0.Scale, corners: [.layerMinXMinYCorner,.layerMaxXMinYCorner])
        
        subviews{
            userView.subviews{
                nameLabel
                genderImage
                lineView
                ageLabel
                iconCircleView.subviews{
                    iconImageView.subviews{
                        shadowView
                    }
                }
            }
            blockButton.subviews{
                blockLabel
            }
            cancelButton
        }
        
        userView.leading(16.0.Scale).trailing(16.0.Scale).top(25.0.Scale).height(68.0.Scale)
        nameLabel.leading(20.0.Scale).top(13.0.Scale)
        genderImage.leading(20.0.Scale).top(39.0.Scale).size(16.0.Scale)
        lineView.leading(40).height(10).width(1.5)
        lineView.CenterY == genderImage.CenterY
        ageLabel.leading(46)
        ageLabel.CenterY == lineView.CenterY
        iconCircleView.trailing(20.0.Scale).size(44.0.Scale).centerVertically()
        iconImageView.size(36.0.Scale).centerVertically().centerHorizontally()
        shadowView.fillContainer()
        blockButton.leading(16.0.Scale).trailing(16.0.Scale).height(61.0.Scale)
        blockButton.Top == userView.Bottom + 9
        blockLabel.leading(20).centerVertically()
        cancelButton.leading(16.0.Scale).trailing(16.0.Scale).height(45.0.Scale)
        cancelButton.Top == blockButton.Bottom + 9.0.Scale
        
        blockLabel.style { v in
            v.setImage("Mine_other_block".toImage, for: .normal)
            v.iconSize = CGSize(width: 20, height: 20)
            v.setTitle("拉黑此用户", for: .normal)
            v.setTitleColor("#B21212".toColor, for: .normal)
            v.isUserInteractionEnabled = false
            v.titleLabel?.font = 15.font_medium
            v.contentHorizontalAlignment = .left
        }
        
        blockButton.addTarget(self, action: #selector(clickBlockButton), for: .touchUpInside)
        cancelButton.addTarget(self, action: #selector(clickCancelButton), for: .touchUpInside)
    }
    
   @objc private func clickBlockButton(){
       entryAnimate.animation(dismiss: self){
           self.blockBlock?()
       }
    }
    
    @objc private func clickCancelButton(){
        entryAnimate.animation(dismiss: self)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


class ClubOtherInfoBlockView: UIView, RaeAnimationProtocol, RaeAnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 299)
    }
    
    func animationContainerViewStyle() -> RaeAnimationViewStyle {
        .bottom
    }
    
    private let contentView = c_make_ex(UIView.self)
        .corner(8.0.Scale).bgColor("#F7F8FA").end()
    private let titleLabel = c_make_ex(UILabel.self)
        .color("#2E3033").font(15.font_semiBold).end()
    private let contentLabel = c_make_ex(UILabel.self)
        .color("#47494D").font(14.font_medium).line(0)
        .text("你将无法查看对方的动态。对方不会收到被拉黑的通知。").end()
    private let sureButton = c_make_ex(UIButton.self)
        .corner(8.0.Scale).bgColor(.white).text("确认")
        .font(15.font_semiBold).color("#B21212").end()
    private let cancelButton = c_make_ex(UIButton.self)
        .corner(8.0.Scale).bgColor(.white).text("取消")
        .font(15.font_semiBold).color("#2E3033").end()
    
    
    var model: ClubMineUserModel?{
        didSet{
            guard let md = model else { return }
            
            titleLabel.text = "将“\(md.user_name)”拉黑"
        }
    }
    
    var sureBlock: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = "#E8E9EB".toColor
        rae.corner(12.0.Scale, corners: [.layerMinXMinYCorner,.layerMaxXMinYCorner])
        
        subviews{
            contentView.subviews{
                titleLabel
                contentLabel
            }
            sureButton
            cancelButton
        }
        
        contentView.leading(16.0.Scale).trailing(16.0.Scale).top(25.0.Scale).height(113.0.Scale)
        titleLabel.leading(24.0.Scale).top(24.0.Scale)
        contentLabel.leading(24.0.Scale).trailing(24.0.Scale).top(49.0.Scale)
        sureButton.leading(16.0.Scale).trailing(16.0.Scale).height(45.0.Scale)
        sureButton.Top == contentView.Bottom + 12.0.Scale
        cancelButton.leading(16.0.Scale).trailing(16.0.Scale).height(45.0.Scale)
        cancelButton.Top == sureButton.Bottom + 12.0.Scale
        
        sureButton.addTarget(self, action: #selector(clickSureButton), for: .touchUpInside)
        cancelButton.addTarget(self, action: #selector(clickCancelButton), for: .touchUpInside)
    }
    
   @objc private func clickSureButton(){
       entryAnimate.animation(dismiss: self){
           self.sureBlock?()
       }
    }
    
    @objc private func clickCancelButton(){
        entryAnimate.animation(dismiss: self)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


class ClubInfoEmptyCell: UITableViewCell {
    
    private let iconImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("Common_empty").end()
    private let titleLabel = c_make_ex(UILabel.self)
        .color("#2E3033").font(14.font_semiBold).alignment(.center)
        .text("空空如也哟~").end()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.subviews{
            iconImageView
            titleLabel
        }
        
        iconImageView.top(100).width(197.0.Scale).height(150.0.Scale).centerHorizontally()
        titleLabel.leading(20).trailing(20).bottom(20)
        titleLabel.Top == iconImageView.Bottom + 24.0.Scale
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
